package com.itheima.server.controller;

import com.itheima.server.service.UserService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class LoginController {

    @Resource
    private UserService userService;

    /**
     * 登录发验证码
     * @param param
     * @return
     */
    @PostMapping("login")
    public ResponseEntity<String> sendMsg(@RequestBody Map<String, String> param) {
        String phone = param.get("phone");
        userService.sendMsg(phone);
        ResponseEntity.status(HttpStatus.OK).build();
        return ResponseEntity.ok("成功");
    }

    /**
     * 登录
     * @param map
     * @return
     */
    @PostMapping("/loginVerification")
    public ResponseEntity<Map> loginVerification(@RequestBody Map<String, String> map) {
        //调用map集合获取请求参数
        String phone = map.get("phone");
        String code = map.get("verificationCode");
        Map<String, Object> resultMap = userService.loginVerification(phone, code);
        return ResponseEntity.ok(resultMap);
    }


}
